package com.taylor.seckill.controller;

import com.taylor.seckill.service.IUserService;
import com.taylor.seckill.vo.LoginVo;
import com.taylor.seckill.vo.ResponseBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;


/**
 * @Description: TODO
 * @author taylor
 * @date  2021/4/9 0:11
 */
@Controller
@RequestMapping("/login")
@Slf4j
public class LoginController {

    @Autowired
    IUserService service;

    /**
     * toLogin 跳转登录
     */
    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }

    /**
     * 登录功能
     * @param loginVo
     * @return
     */
    @RequestMapping("/doLogin")
    @ResponseBody
    public ResponseBean doLogin(@Valid LoginVo loginVo , HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        ResponseBean responseBean = service.doLogin(loginVo, httpServletRequest, httpServletResponse);
        log.info(responseBean.toString());
        return responseBean;
    }

}
